import collections


class Solution(object):
    def wonderfulSubstrings(self, word):
        n = len(word)
        prefix = collections.defaultdict(int)
        now = [0 for _ in range(10)]
        prefix[tuple(now)] = 1
        ans = 0
        for w in word:
            id = ord(w) - ord('a')
            now[id] = (now[id] + 1) % 2
            ans += prefix[tuple(now)]
            for j in range(10):
                q = now.copy()
                q[j] = 1 - q[j]
                ans += prefix[tuple(q)]
            prefix[tuple(now)] += 1
        return ans


data = Solution()
word = "aba"
print(data.wonderfulSubstrings(word))
